#ifndef BASETEXTURE_H
#define BASETEXTURE_H

#include "Resource.h"
#include "CommonTypes.h"
#include "MemUtils.h"

namespace Cvekas {

/// Base of all texture types
class BaseTexture : public Resource
{
public:
	/// Constructor
    BaseTexture(ResourceId id, D3DDevicePtr device, const std::string& name, D3DFORMAT format)
		: 
	Resource(name, id), 
	texture(NULL), 
	device(device), 
	format(format), 
	is_released(false) 
	{};

	/// Destructor
	virtual ~BaseTexture() 
	{ 
		if(!is_released) 
		{
			safeRelease(texture);
			is_released = true;
		}
	};
        
	/// Returns pointer to IDirect3DBaseTexture9 stored in this %BaseTexture
	IDirect3DBaseTexture9* getD3DTexture() const { return texture; };
	
	/// Returns format of texture
	const D3DFORMAT getFormat() const { return format; };
	
	/// TEMPORARY: Returns description of top level of texture (first mipmap, or whole texture if no mipmaps)
	const D3DSURFACE_DESC& getTopLevelDescription() const { return description; };

	virtual void onDeviceLost() = 0;
	virtual void onDeviceReset() = 0;

protected:
    IDirect3DBaseTexture9* texture;
	D3DDevicePtr device;
	D3DFORMAT format;
	D3DSURFACE_DESC description;
	bool is_released;

};

typedef boost::shared_ptr<BaseTexture> TexturePtr;

} // namespace

#endif